package com.servletspringboot.config;

import com.servletspringboot.filter.ManuallyCreateFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;

@Configuration
public class FilterConfig {

    /**
     * 和手动注册Servlet的方式差不多
     * @return 注意返回值的类型是FilterRegistrationBean 对象，和Servlet不同
     */
    @Bean
    public FilterRegistrationBean<Filter> createFilterAndRegister(){

        FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<>();

        ManuallyCreateFilter manuallyCreateFilter = new ManuallyCreateFilter();

        bean.setFilter(manuallyCreateFilter);

        bean.addUrlPatterns("/manuallyCreateServlet","*.action");

        return bean;
    }
}
